FROM python:3.9.13-alpine3.16 as base
FROM base as builder
COPY requirements.txt /requirements.txt
RUN pip install --user -r /requirements.txt -i https://mirror.gree.com/pypi/simple/

FROM base
COPY --from=builder /root/.local /root/.local
COPY . /app
WORKDIR /app
ENV PATH=/root/.local/bin:$PATH

# 正式服务器参数
ARG mysql_host="172.80.10.150"
ARG mysql_port=3306
ARG mysql_username="root"
ARG mysql_password="233233233"
ARG mysql_db="liot"
ARG redis_host="172.80.10.150"
ARG redis_port=6379
ARG redis_db=0
ARG mqtt_url="mqtt://172.80.10.150:1883"
ARG http_url="http://172.80.10.150:7000/api/v1/source/"

ENV MYSQL_USERNAME=${mysql_username} \
    MYSQL_PASSWORD=${mysql_password} \
    MYSQL_HOST=${mysql_host} \
    MYSQL_PORT=${mysql_port} \
    MYSQL_DB=${mysql_db} \
    REDIS_HOST=${redis_host} \
    REDIS_PORT=${redis_port} \
    REDIS_DB=${redis_db}\
    MQTT_URL=${mqtt_url}\
    HTTP_URL=${http_url}

CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000"]
